from django.contrib.auth.backends import ModelBackend
import re
from .models import User
#用户进行多账户登陆

class Muteuser(ModelBackend):
    def authenticate(self, request, username=None, password=None, **kwargs):

        try:
            if re.match('^1[35789]\d{9}$',username):
               user=User.objects.get(phone=username)

            else:
               user=User.objects.get(username=username)


        except :      #不存在 DoesNotExist这个属性
               user=None
        if user and user.check_password(password):
            return user

